unit Amy.Chromium.InternalHandler;

interface

  uses Winapi.Windows, Winapi.Messages, Amy.Chromium.Task, Amy.Chromium.Utils;

procedure windowMax(Context: TAmyChromiumTask);
procedure windowMin(Context: TAmyChromiumTask);
procedure windowRestore(Context: TAmyChromiumTask);
procedure windowMove(Context: TAmyChromiumTask);
procedure windowClose(Context: TAmyChromiumTask);
procedure windowSize(Context: TAmyChromiumTask);

implementation

procedure windowMax(Context: TAmyChromiumTask);
var
  browserHandle: THandle;
begin
  browserHandle := GetBrowserWindow(Context.Data.Browser);
  if IsZoomed(browserHandle) then
  begin
    PostMessage(browserHandle, WM_SYSCOMMAND, SC_RESTORE, 0);
  end
  else begin
    PostMessage(browserHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
  end;
end;

procedure windowMin(Context: TAmyChromiumTask);
var
  browserHandle: THandle;
begin
  browserHandle := GetBrowserWindow(Context.Data.Browser);
  PostMessage(browserHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
end;

procedure windowRestore(Context: TAmyChromiumTask);
var
  browserHandle: THandle;
begin
  browserHandle := GetBrowserWindow(Context.Data.Browser);
  if IsZoomed(browserHandle) then
  begin
    PostMessage(browserHandle, WM_SYSCOMMAND, SC_RESTORE, 0);
  end
  else begin
   PostMessage(browserHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
  end;
end;

procedure windowMove(Context: TAmyChromiumTask);
var
  browserHandle: THandle;
begin
  browserHandle := GetBrowserWindow(Context.Data.Browser);
  ReleaseCapture;
  PostMessage(browserHandle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION,0);
end;

procedure windowClose(Context: TAmyChromiumTask);
var
  browserHandle: THandle;
begin
  browserHandle := GetBrowserWindow(Context.Data.Browser);
  PostMessage(browserHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
end;

procedure windowSize(Context: TAmyChromiumTask);
var
  browserHandle: THandle;
begin
//  browserHandle := GetBrowserWindow(Context.Data.Browser);
//  ReleaseCapture;
//  SendMessage(browserHandle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION,0);
end;

end.
